<template>
	<view class="page meInfo">
		<view class="meInfo-top white">
			<view class="item" @click="faceImg()">
				<text class="subtitle">头像</text>
				<view class="content">
					<!-- {{userInfo.faceImg}} -->
					<image :src='userInfo.faceImg||"/static/icos/default-face.png"' class="face"></image>
					<image src="/static/icos/left-gray-arrow.png" class="icon"></image>
				</view>
			</view>

			<navigator class="item" :url="'../updateNickname/updateNickname?nickname='+userInfo.nickname">
				<text class="subtitle">昵称</text>
				<view class="content">
					<view class="msg">{{userInfo.nickname}}</view>
					<image src="/static/icos/left-gray-arrow.png" class="icon"></image>
				</view>
			</navigator>
			<navigator class="item" :url="'../updateBirthday/updateBirthday?birthday='+userInfo.birthday">
				<text class="subtitle">生日</text>
				<view class="content">
					<view class="msg">{{userInfo.birthday || "未选择"}}</view>
					<image src="/static/icos/left-gray-arrow.png" class="icon"></image>
				</view>
			</navigator>
			<navigator class="item" :url="'../updateSex/updateSex?sex='+userInfo.sex">
				<text class="subtitle">性别</text>
				<view class="content">
					<view class="msg">{{ sexInit }}</view>
					<image src="/static/icos/left-gray-arrow.png" class="icon"></image>
				</view>
			</navigator>
		</view>
		
		<view class="footer-wapper">
			<view class="footer-item" @click="clearStorage">清理缓存</view>
			<view class="footer-item" @click="exit">退出登录</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:{}
			}
		},
		methods: {
			faceImg(){
				let me=this
				
				uni.showActionSheet({
					itemList:["查看头像","上传我的头像"],
					success(res) {
						if(res.tapIndex==0){
							let arr=[me.userInfo.faceImg||"/static/icos/default-face.png"]
							uni.previewImage({
								urls:arr,
								current:arr[0]
							})
						}else if(res.tapIndex==1){
							// #ifndef MP-WEIXIN
							uni.navigateTo({
								url:"../mePace/mePace"
							})
							// #endif
							// #ifdef MP-WEIXIN
							uni.chooseImage({
								sizeType:["compessed"],
								count:1,
								success(resImg) {
									let tempFilePaths=resImg.tempFilePaths[0]
									uni.navigateTo({
										url:"../mePace/mePace?tempFilePaths="+tempFilePaths
									})
								}
								
							})
							// #endif
							
						}
					}
				})
			},
			clearStorage(){
				uni.clearStorage()
				uni.showToast({
					title:"清除缓存成功",
					duration:1500,
					mask:true
				})
			},
			getUserInfo(){
				let userInfo = uni.getStorageSync('user')
				if(userInfo){
					this.userInfo=userInfo[0]
				}
			},
			exit(){
				uni.removeStorageSync("user")
				uni.showToast({
					title:"已退出",
					duration:1000
				})
				setTimeout(()=>{
					uni.switchTab({
						url:'../me/me'
					})
				},1000)
				
			}
		},
		onShow() {
			this.getUserInfo()
		},
		computed:{
			sexInit(){
				if(this.userInfo.sex==1){
					return "男"
				}else if(this.userInfo.sex==0){
					return "女"
				}else{
					return "未选择"
				}
			}
		}
	}
</script>

<style>

@import url("meInfo.css");
</style>
